home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / pcpilot.exe / lha / VIDEO.ASM < prev   
Assembly Source File  |  1989-01-03  |  10KB  |  453 lines

  1. ;
  2. ; VIDEO2.ASM - Draw box and set attribute without CGA snow.
  3. ;              These functions are from the book "User Interfaces in C"
  4. ;              and are on pages 23-37.
  5.  
  6.  
  7. bios_data        equ        40h
  8. crt_mode_set    equ        65h
  9. lprog            equ        1
  10. ldata            equ        0
  11.  
  12. DGROUP            group    _DATA
  13. _DATA            segment    word public 'DATA'
  14.                 assume ds:DGROUP
  15.  
  16. EXTRN        _VideoSeg:word            ; see scr.h
  17.  
  18. ULC            db        218,201,213,214
  19. URC            db        191,187,184,183
  20. LLC            db        192,200,212,211
  21. LRC            db        217,188,190,189
  22. HL            db        196,205,205,196
  23. VL            db        179,186,179,186
  24.  
  25. _DATA            ends
  26.  
  27.  
  28. _TEXT            segment para public 'CODE'
  29.                 assume cs:_TEXT
  30.  
  31.                 public     _SetAttrib, _DrawBox, _WaitKey, _ClearScr
  32.                 public  _SaveScreen, _RestoreScreen, _PutChr
  33.  
  34. ;
  35. ; void SetAttrib(int att, int col1, int row1, int col2, int row2);
  36. ;
  37. _SetAttrib        proc    near
  38. att                equ        [bp+4]
  39. col1            equ        [bp+6]
  40. row1            equ        [bp+8]
  41. col2            equ        [bp+10]
  42. row2            equ        [bp+12]
  43. rows            equ        [bp-2]
  44. cols            equ        [bp-4]
  45.  
  46.                 push    bp
  47.                 mov        bp,sp
  48.                 sub        sp,4
  49.  
  50.                 push    di                ;Save the registers
  51.                 push    es
  52.                 mov        ax,row1            ;Figure the video offset
  53.                 mov        bx,col1
  54.                 call    fig_vid_off
  55.                 mov        di,ax            ;DI=Video offset
  56.                 inc        di                ;Bump it to the first attribute
  57.                 mov        ax,_VideoSeg       ;ES=Video segment
  58.                 mov        es,ax
  59.                 mov        ax,row2            ;Figure the number of rows
  60.                 sub        ax,row1
  61.                 inc        ax
  62.                 mov        rows,ax            ;Save it
  63.                 mov        ax,col2            ;Figure the number of columns
  64.                 sub        ax,col1
  65.                 inc        ax
  66.                 mov        cols,ax            ;Save it
  67.                 cld                        ;Flag increment
  68.                 mov        al,byte ptr att    ;AL=Display attribute
  69.                 call    disable_cga        ;Disable CGA if necessary
  70. setattrib1:        push    di                ;Save the video offset
  71.                 mov        cx,cols            ;CX=Number of columns
  72. setattrib2:        stosb                    ;Set the attribute byte
  73.                 inc        di                ;Bump the video pointer
  74.                 loop    setattrib2        ;Loop till done
  75.                 pop        di                ;Restore the video offset
  76.                 add        di,160            ;Point it to the next row
  77.                 dec        word ptr rows    ;Loop till done
  78.                 jnz        setattrib1
  79.                 call    enable_cga        ;Enable the CGA if necessary
  80.                 pop        es                ;Restore the registers
  81.                 pop        di
  82.  
  83.                 mov        sp,bp
  84.                 pop        bp
  85.  
  86.                 ret                        ;Return
  87. _SetAttrib        endp
  88.  
  89. ;
  90. ; void DrawBox(int col1, int row1, int col2, int row2, int flag, int att);
  91. ;
  92. _DrawBox        proc    near
  93. col1            equ        [bp+4]
  94. row1            equ        [bp+6]
  95. col2            equ        [bp+8]
  96. row2            equ        [bp+10]
  97. flag            equ        [bp+12]
  98. att                equ        [bp+14]
  99. rows            equ        [bp-2]
  100. cols            equ        [bp-4]
  101.  
  102.  
  103.                 push    bp
  104.                 mov        bp,sp
  105.                 sub        sp,10
  106.  
  107.                 push    di                ;Save the registers
  108.                 push    si
  109.  
  110.                 mov        si,word ptr flag    ;SI=Line style flag
  111.                 push    es
  112.                 mov        ax,row1            ;Figure the video offset
  113.                 mov        bx,col1
  114.                 call    fig_vid_off
  115.                 mov        di,ax            ;DI=Video offset
  116.                 mov        ax,_VideoSeg       ;ES=Video segment
  117.                 mov        es,ax
  118.                 mov        ax,row2            ;Figure the # of rows - 2
  119.                 sub        ax,row1
  120.                 dec        ax
  121.                 mov        rows,ax            ;Save it
  122.                 mov        ax,col2            ;Figure the # of cols - 2
  123.                 sub        ax,col1
  124.                 dec        ax
  125.                 mov        cols,ax            ;Save it
  126.                 cld                        ;Flag increment
  127.                 mov        ah,att            ;AH=Display attribute
  128.                 call    disable_cga        ;Disable CGA if necessary
  129.                 push    di                ;Save the video offset
  130.  
  131.                 ;Upper left corner
  132.                 mov        al,byte ptr ULC[si]
  133.  
  134. drawbox1:        stosw                    ;Save the character/attribute pair
  135.  
  136.                 ;Top horzontal line
  137.                 mov        al,byte ptr HL[si]
  138.  
  139. drawbox2:        mov        cx,cols            ;CX=Line length
  140.                 rep        stosw            ;Display the line
  141.  
  142.                 ;Upper right corner
  143.                 mov        al,byte ptr URC[si]
  144.  
  145. drawbox3:        stosw                    ;Save the character/attribute pair
  146.                 pop        di                ;Restore the video pointer
  147.                 add        di,160            ;Point it to the next row
  148. drawbox4:        push    di                ;Save the video pointer
  149.  
  150.                 ;Vertical lines
  151.                 mov        al,byte ptr VL[si]
  152.  
  153. drawbox5:        stosw                    ;Save the character/attribute pair
  154.                 add        di,cols            ;Point to
  155.                 add        di,cols            ;the right side
  156.                 stosw
  157.                 pop        di                ;Restore the video pointer
  158.                 add        di,160            ;Point it to the next row
  159.                 dec        word ptr rows    ;Loop till the
  160.                 jnz        drawbox4        ;sides are complete
  161.  
  162.                 ;Lower left corner
  163.                 mov        al,byte ptr LLC[si]
  164.  
  165. drawbox6:        stosw
  166.  
  167.                 ;Bottom horizontal line
  168.                 mov        al,byte ptr HL[si]
  169.  
  170. drawbox7:        mov        cx,cols            ;CX=Line length
  171.                 rep        stosw            ;Display the line
  172.  
  173.                 ;Lower right corner
  174.                 mov        al,byte ptr LRC[si]
  175.  
  176. drawbox8:        stosw
  177.                 call    enable_cga        ;Enable CGA if necessary
  178.                 pop        es                ;Restore the registers
  179.                 pop        si
  180.                 pop        di
  181.  
  182.                 mov        sp,bp
  183.                 pop        bp
  184.                 ret                        ;Return
  185. _DrawBox        endp
  186.  
  187.  
  188. ;
  189. ; void PutChr(inr col, int row, int attr, char chr);
  190. ;
  191. _PutChr            proc    near
  192. col        equ        <4[bp]>
  193. row        equ        <6[bp]>
  194. attr    equ        <8[bp]>
  195. chr        equ        <10[bp]>
  196.  
  197.         push    bp
  198.         mov        bp,sp
  199.         sub        sp,10
  200.  
  201.         push    di                    ; Save the registers
  202.         push    si
  203.         push    es
  204.  
  205.         mov        ax,row
  206.         mov        bx,col
  207.         call    fig_vid_off
  208.         mov        di,ax
  209.         mov        ax,_VideoSeg            ; CGA only
  210.         mov        es,ax
  211.         cld                            ; Flag increment
  212.         mov        ah,attr
  213.         ;call    disable_cga
  214.         push    di
  215.         mov        al,chr
  216.         stosw                        ; Save the char/attr pair
  217.         pop        di
  218.         ;call    enable_cga
  219.         pop        es
  220.         pop        si
  221.         pop        di
  222.  
  223.         mov        sp,bp
  224.         pop        bp
  225.         ret
  226. _PutChr        endp
  227.  
  228.  
  229. ;
  230. ; void SaveScreen(int col1, int row1, int col2, int row2, char array);
  231. ;
  232. _SaveScreen        proc    near
  233. col1    equ        <4[bp]>
  234. row1    equ        <6[bp]>
  235. col2    equ        <8[bp]>
  236. row2    equ        <10[bp]>
  237. array    equ        <12[bp]>
  238. rows    equ        <-2[bp]>
  239. cols    equ        <-4[bp]>
  240.  
  241.                 push    bp
  242.                 mov        bp,sp
  243.                 sub        sp,4
  244.  
  245.                 push    di                ;Save the registers
  246.                 push    si
  247.                 push    es
  248.  
  249.                 mov        ax,row1            ;Figure the video offset
  250.                 mov        bx,col1
  251.                 call    fig_vid_off
  252.                 mov        si,ax            ;SI=Video offset
  253.                 mov        ax,row2            ;Figure the number of rows
  254.                 sub        ax,row1
  255.                 inc        ax
  256.                 mov        rows,ax            ;rows = row2 - row1 + 1
  257.                 mov        ax,col2            ;Figure the number of columns
  258.                 sub        ax,col1
  259.                 inc        ax                ;cols = col2 - col1 + 1
  260.                 mov        cols,ax            ;Save it
  261.                 cld                        ;Flag increment
  262.                 call    disable_cga
  263.                 push    ds
  264.                 if        ldata
  265.                 les        di,array        ;ES:DI=Array pointer
  266.                 else
  267.                 push    ds
  268.                 pop        es
  269.                 mov        di,array
  270.                 endif
  271.                 mov        ds,_VideoSeg
  272. savescreen1:    push    si
  273.                 mov        cx,cols
  274.                 rep        movsw
  275.                 pop        si
  276.                 add        si,160
  277.                 dec        word ptr rows
  278.                 jnz        savescreen1
  279.                 pop        ds
  280.                 call    enable_cga
  281.                 pop        es
  282.                 pop        si
  283.                 pop        di
  284.  
  285.                 mov        sp,bp
  286.                 pop        bp
  287.                 ret
  288. _SaveScreen        endp
  289.  
  290.  
  291. ;
  292. ;void RestoreScreen(int col1, int row1, int col2, int row2, char array);
  293. ;
  294. _RestoreScreen    proc    near
  295. col1    equ        <4[bp]>
  296. row1    equ        <6[bp]>
  297. col2    equ        <8[bp]>
  298. row2    equ        <10[bp]>
  299. array    equ        <12[bp]>
  300. rows    equ        <-2[bp]>
  301. cols    equ        <-4[bp]>
  302.  
  303.                 push    bp                ;Save BP
  304.                 mov        bp,sp
  305.                 sub        sp,4
  306.  
  307.                 push    di                ;Save the registers
  308.                 push    si
  309.                 push    es
  310.                 mov        ax,row1            ;Figure the video offset
  311.                 mov        bx,col1
  312.                 call    fig_vid_off
  313.                 mov        di,ax
  314.                 mov        es,_VideoSeg
  315.                 mov        ax,row2            ;Figure the number of rows
  316.                 sub        ax,row1
  317.                 inc        ax
  318.                 mov        rows,ax
  319.                 mov        ax,col2            ;Figure the number of columns
  320.                 sub        ax,col1
  321.                 inc        ax
  322.                 mov        cols,ax
  323.                 cld
  324.                 call    disable_cga
  325.                 if        ldata
  326.                 push    ds
  327.                 lds        si,array
  328.                 else
  329.                 mov        si,array
  330.                 endif
  331. restorescreen1:    push    di                ;Save the video offset
  332.                 mov        cx,cols
  333.                 rep        movsw
  334.                 pop        di
  335.                 add        di,160
  336.                 dec        word ptr rows
  337.                 jz        restorescreen1
  338.                 if        ldata
  339.                 pop        ds
  340.                 endif
  341.                 call    enable_cga
  342.                 pop        es
  343.                 pop        si
  344.                 pop        di
  345.  
  346.                 mov        sp,bp
  347.                 pop        bp
  348.                 ret
  349. _RestoreScreen    endp
  350.  
  351.  
  352. ;
  353. ; void WaitKey(void);
  354. ;
  355. _WaitKey        proc    near
  356. iskey:            mov        ah,01h                ;Has a key
  357.                 int        16h                    ;been pressed?
  358.                 jz        iskey                ;Loop if not
  359.                 mov        ah,0                ;Get the key
  360.                 int        16h
  361.                 or        al,al                ;Jump if
  362.                 jz        wait_key1            ;extended key
  363.                 xor        ah,ah                ;Erase the scan code
  364.                 jmp        short wait_key2        ;Jump
  365. wait_key1:        xchg    ah,al                ;AX=Scan code
  366.                 inc        ah                    ;AX=Scan code + 256
  367. wait_key2:        ret                            ;Return
  368. _WaitKey        endp
  369.  
  370.  
  371. ;
  372. ; void ClearScr(int col1, int row1, int col2, int row2, int att);
  373. ;
  374. _ClearScr        proc    near
  375. col1            equ        [bp+4]
  376. row1            equ        [bp+6]
  377. col2            equ        [bp+8]
  378. row2            equ        [bp+10]
  379. att                equ        [bp+12]
  380.  
  381.                 mov        ah,06h
  382.                 mov        al,0
  383.                 mov        dh,row2
  384.                 mov        dl,col2
  385.                 mov        ch,